package org.itboys.seller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.itboys.ace.dto.SellerOrderListDto;
import org.itboys.admin.constant.AdminSessionConstant;
import org.itboys.commons.CommonConstants.DF;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.servlet.ServletContextHolder;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mongodb.utils.page.Page;
import org.itboys.mongodb.utils.query.QueryParamUtils;
import org.itboys.trade.constant.OrderConstant;
import org.itboys.trade.entity.Order;
import org.itboys.trade.entity.OrderItem;
import org.itboys.trade.entity.Refund;
import org.itboys.trade.entity.TicketOrder;
import org.itboys.trade.entity.TicketOrderItem;
import org.itboys.trade.service.OrderItemService;
import org.itboys.trade.service.OrderService;
import org.itboys.trade.service.RefundService;
import org.itboys.trade.service.TicketOrderItemService;
import org.itboys.trade.service.TicketOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;



/**
 * Created by Administrator on 2016/7/7.
 */
@RestController
@RequestMapping("/seller/refund")
public class SellerRefundController extends BaseController {
	@Autowired
	private OrderService orderService;
	@Autowired
	private OrderItemService itemService;
	@Autowired
	private TicketOrderService ticketOrderService;
	@Autowired
	private TicketOrderItemService ticketOrderItemService;
	@Autowired
	private RefundService refundService;
	@RequestMapping("/toRefundListVM")
	public ModelAndView toListVM(HttpServletRequest request,HttpServletResponse response){
		return new ModelAndView("/order/refundList");
	}
	@RequestMapping("/list")
	public void list(HttpServletRequest request,HttpServletResponse response){
		Map<String, Object> sqlMap = QueryParamUtils.builderQueryMap(request);// 组装查询参数
		Long centerId=(Long)request.getSession().getAttribute(AdminSessionConstant.CENTER_ID);
		sqlMap.put("pageNo", Integer.valueOf(request.getParameter("page")));
		sqlMap.put("pageSize", Integer.valueOf(request.getParameter("rows")));
		sqlMap.put("deleted", false);
		sqlMap.put("centerId",centerId);
		sqlMap.put("orderByKey", "-ct");
		Page<Refund> page = refundService.page(sqlMap);// 组装page对象
		page.getData().forEach(r->{
			r.setCreateTime(DF.FORMAT_DEFAULT.format(r.getCt()));
		});
		JsonPageUtils.renderJsonPage(page.getTotal(),page.getData(),
				response);
	}
	@RequestMapping("/pass")
	public void pass(@RequestParam Long id,HttpServletRequest request,HttpServletResponse response){
		Refund refund=refundService.getById(id);
		refund.setStatus(Refund.status_pass);
		refundService.update(refund);
	}
}
